package converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.naming.InitialContext;

import dao.DoctorSpecialtyDAO;
import entity.DoctorSpecialty;

@FacesConverter("stringToDoctorSpecialtyConverter")
public class StringToDoctorSpecialtyConverter implements Converter {
	
	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		DoctorSpecialtyDAO doctorSpecialtyDAO = null;
		try {
			InitialContext ctx = new InitialContext();
			doctorSpecialtyDAO = (DoctorSpecialtyDAO) ctx.lookup("java:global/PaidClinic/JPADoctorSpecialtyDAO!dao.DoctorSpecialtyDAO");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return doctorSpecialtyDAO.selectDoctorSpecialtyByName(value);
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) { 		
		return ((DoctorSpecialty) value).toString();
	}
	
}
